<?php

namespace app\index\controller;

use app\common\controller\HomeBase;
use think\Db;
use think\Request;

class Share extends HomeBase
{
    public function index()
    {
		
		$params = Request::instance()->param();
        if(!isset($params['sign'])  && !isset($params['timestamp']) ){
            return json_encode(['code'=>'-1','msg'=>'error','list'=>'签名错误']);
        }

        $sign = $params['sign'];
        $timestamp = $params['timestamp'];
        $articleid = $params['articleid'];

        //秘钥
        $secret = '1dFlxLhiuLqnUZe9kA';

        //签名获得
        $service_api = md5($secret."articleid".$articleid.$timestamp.$secret);

        //对比签名
        if($service_api != $sign){
            return json(['code'=>'-1','msg'=>'error','list'=>'签名错误']);
        }
		
        $articleid   = Request::instance()->param('articleid');

        $responce = Db::table('lsj_article')
			->field('thumb,content,title,create_time,reading')
            ->where(['id'=>$articleid,'status'=>1])
            ->find();
		if(!$responce){
			return "文章已不存在!";
		}
//
//		if($responce['buy_class'] != 1){
//		    if($responce['photo']){
//                $photos = json_decode($responce['photo']);
//                $photo_html = '';
//                foreach($photos as $photo){
//                    $photo_html .= "<img src = '{$photo}' />";
//                }
//                $responce['content'] = "<p><br>{$responce['content']}</br>{$photo_html}</p>";
//            }
//        }

        return $this->fetch('index',['responces' => $responce]);
    }
}